# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_realname=wasm-component-ld
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.5.13
pkgrel=1
pkgdesc="Command line linker for creating WebAssembly components (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/bytecodealliance/wasm-component-ld"
msys2_references=(
  'archlinux: wasm-component-ld'
  'purl: pkg:cargo/wasm-component-ld'
)
license=('spdx:Apache-2.0 WITH LLVM-exception AND Apache-2.0 AND MIT')
depends=("${MINGW_PACKAGE_PREFIX}-lld")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
checkdepends=("${MINGW_PACKAGE_PREFIX}-rust-wasm")
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('bd1f826cd4d0d47dba5fa55396c72bbab8b61f80b23a51a32b4b29e50ec172f8')

prepare() {
  cd "${_realname}-${pkgver}"

  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${_realname}-${pkgver}"

  cargo build --release --frozen
}

check() {
  cd "${_realname}-${pkgver}"

  cargo test --release --frozen
}

package() {
  cd "${_realname}-${pkgver}"

  install -Dm755 target/release/wasm-component-ld "${pkgdir}${MINGW_PREFIX}/bin/wasm-component-ld"
  install -Dm644 LICENSE* -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
